﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using YmSoft.WPF.Core;
using YmSoft.Data;

namespace YmSoft.WPF.ShouJi
{
    public class MVShouJi : BaseNotifyPropertyChanged
    {
        CfShouji cfShouji = null;
        public MVShouJi()
        {

        }
        public CfShouji CfShouji
        {
            get
            {

                if (cfShouji == null)
                {
                    if (IsInDesignMode)
                    {
                        cfShouji = new CfShouji();
                    }
                    else
                    {
                        var cfShoujiRepository = new CfShoujiRepository();
                        cfShouji = cfShoujiRepository.GetCfExtension();
                    }
                }
                return cfShouji;
            }
        }

        ICommand saveCommand = null;
        public ICommand SaveCommand
        {
            get
            {
                if (saveCommand == null)
                {
                    saveCommand = new RelayCommand(() =>
                    {

                        if (!IsInDesignMode)
                        {
                            var cfShoujiRepository = new CfShoujiRepository();
                            cfShoujiRepository.SaveCfExtension(CfShouji);
                            cfShoujiRepository.SubmitChanges();
                        }
                    });
                }
                return saveCommand;
            }
        }
    }
}
